@extends('layout.master')

@section('title','医生类型')

@section('css')
    @parent
    <!-- Daterange picker plugins css -->
    <link href="{{ asset('plugins/bower_components/bootstrap-daterangepicker/daterangepicker.css') }}" rel="stylesheet">
    <style>
        .floating-labels .radioInput label {
            position: static;
        }

    </style>
@endsection
@section('main')
    <!-- form itself -->
    <form id="test-form" class="mfp-hide white-popup-block floating-labels doctor-type-add">
        <h3>添加类型</h3>
        <hr>
        <div class="form-group m-b-40 m-t-10">
            <input type="text" class="form-control" id="name-publish" name="title" required><span
                    class="highlight"></span> <span class="bar"></span>
            <label for="input1">类型名称</label>
        </div>
        <div class="form-group m-b-40">
            <input type="text" class="form-control" id="display-publish" name="display" required><span
                    class="highlight"></span> <span class="bar"></span>
            <label for="input2">排序</label>
        </div>
        <div class="skin skin-flat">
            <div class="form-group radioInput m-b-40">
                <label>状态</label>
                <div class="radio-list">
                    @foreach(App\DoctorType::$StatusDisplay as $key => $value)
                        <label for="flat-radio-{{ $key }}" class="p-l-20 radio-inline p-0">
                            <input type="radio" class="check radioCheck" id="flat-radio-{{ $key }}"
                                   name="status" value="{{ $key }}"
                                   data-radio="iradio_flat-purple">
                            {{ $value }}
                        </label>
                    @endforeach
                </div>
            </div>
        </div>
        <div class="skin skin-flat">
            <div class="form-group radioInput m-b-40">
                <label>是否需要资格证</label>
                <div class="radio-list">
                    @foreach(App\DoctorType::$QualDisplay as $key => $value)
                        <label for="flat-radio-{{ $key }}" class="p-l-20 radio-inline p-0">
                            <input type="radio" class="check radioCheck" id="flat-radio-{{ $key }}"
                                   name="needqualification" value="{{ $key }}"
                                   data-radio="iradio_flat-purple">
                            {{ $value }}
                        </label>
                    @endforeach
                </div>
            </div>
        </div>
        <div class="form-actions">
            <div class="row">
                <div class="col-md-12">
                    <div class="row">
                        <div class="col-md-offset-3 col-md-9">
                            <button type="submit" class="btn btn-success"><i
                                        class="fa fa-check"></i> 保存
                                {!! csrf_field() !!}
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>

    <div class="panel">
        <div class="panel-action" style="margin-top: -9px">
            <a class="popup-with-form btn fcbtn btn btn-outline btn-info btn-1c" href="#test-form">
                <span>添加医生类型</span>
            </a>
        </div>
    </div>
    <div class="white-box">
        <h3 class="box-title m-b-0">医生类型</h3>
        <hr>
        <div class="table-responsive">
            <table id="example23"
                   class="display nowrap table table-striped table-bordered table-hover order-column my-table "
                   cellspacing="0" width="100%" data-url="{{ url(request()->getUri()) }}">
                <thead>
                <tr>
                    <th>名称</th>
                    <th>排序</th>
                    <th>显示状态</th>
                    <th>是否需要资格证</th>
                    <th>创建时间</th>
                    <th>编辑</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
@endsection

@section('js')
    @parent
    <script src="{{ asset('js/myself.js') }}"></script>
    <script>
        $('.doctor-type-add').submit(function (e) {
            e.preventDefault();
            swal({
                    title: "",
                    text: "确定添加么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        type: "POST",
                        url: '/doctor/type/publish',
                        data: $('.doctor-type-add').serialize(),// 你的formid
                        async: false,
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            swal(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            console.log(data.message);
                            if (data.status === 1) {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            } else {
                                swal(data.message);
                            }
                        }
                    })
                }
            );

        });


        //删除
        obj.on('click', '.btn-del', function () {
            var id = $(this).data('id');
            swal({
                    title: "",
                    text: "确定删除么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/doctor/type/del/' + id,
                        type: 'POST',
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            swal(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });


        //状态修改
        obj.on('click', '.btn-status', function () {
            var id = $(this).data('id');
            swal({
                    title: "",
                    text: "确定修改么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/doctor/type/status/modify/' + id,
                        type: 'POST',
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            swal(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });

        //状态修改
        obj.on('click', '.btn-needqualification', function () {
            var id = $(this).data('id');
            swal({
                    title: "",
                    text: "确定修改么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/doctor/type/qual/modify/' + id,
                        type: 'POST',
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            swal(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });
    </script>
@endsection